import baseUrl from "./baseUrl"


var request = function(config){
  return new Promise((resolve,rejected)=>{
    var setting = {
      url: baseUrl + config.url,
      method:config.method ? (config.method).toUpperCase() :  "GET",
      // method: (config.method).toUpperCase() || "GET",
      data:config.data,
      header:{
        // "content-type":"application/x-www-form-urlencoded"
      },
      timeout:5000,
      success(res){
        resolve(res)
      },
      fail(res){
        rejected(res)
      }
    }
    if(config.method){
      if(config.method.toUpperCase() == "POST"){
        setting.header["content-type"] = "application/x-www-form-urlencoded"
      }else{
        setting.header["content-type"] = "application/json"
      }
    }else{
      setting.header["content-type"] = "application/json"
    }
    wx.request(setting)
  })
  
};
export default request
